package com.findme.fecedetection.ui

import android.app.Activity
import android.content.Intent
import com.findme.fecedetection.Const
import com.findme.fecedetection.R
import com.findme.fecedetection.base.ImmersionTitleActivity
import com.findme.fecedetection.net.HttpManager
import com.findme.fecedetection.ui.fragment.UserLoginActivity
import com.tanguy.user.App.Companion.app
import com.tanguy.user.utlis.extend.click
import com.tanguy.user.utlis.extend.requestSucceed
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult

/**
 * Created by dab on 2017/11/20 0020 21:40
 */
class LoginActivity : ImmersionTitleActivity() {
    override fun setContentViewRes(): Int = R.layout.activity_login
    override fun initView() {
        super.initView()
        click(R.id.tv_login) {
//                        startActivityForResult<UserLoginActivity>(Const.RequestCode.LOGE, "register" to false)
            startActivity<MainActivity>()
        }
        click(R.id.tv_register) { startActivityForResult<UserLoginActivity>(Const.RequestCode.LOGE, "register" to true) }
        HttpManager.list().requestSucceed(this) {
            val da=app.map
            for (i in 0 until it.size) {
                val dictionaries = it[i]
                val key = dictionaries.typeCode
                if (da.containsKey(key)) {
                    var hashMap = da[key]
                    if (hashMap == null) {
                        hashMap = HashMap()
                    }
                    hashMap.put(dictionaries.code, dictionaries.name)
                } else {
                    var hashMap = da[key]
                    if (hashMap == null) {
                        hashMap = HashMap()
                    }
                    hashMap.put(dictionaries.code, dictionaries.name)
                    da.put(key,hashMap)
                }
            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == Const.RequestCode.LOGE) {
                finish()
            }
        }
    }
}